﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Silverlight.Testing.Harness;
using Microsoft.Silverlight.Testing.UnitTesting.Metadata;
using System.Text;

namespace RStein.Posterous.API.Test.SL
{
  public class SpecialLogger : LogProvider
  {    
    public const string MESSAGE_FORMAT = "TestClass {0}: Method: {1} Result: {2} ScenarioResult:{3}";
    public SpecialLogger()
    {
      ResultText = new StringBuilder();
    } 
    public StringBuilder ResultText
    {
      get;
      private set;
    }
    

    public override void Process(LogMessage logMessage)
    {

      if (!IsTestCaseCompletion(logMessage))
      {
         
          return;
      }

      TestOutcome result = (TestOutcome)logMessage[LogDecorator.TestOutcome]; 
      ITestMethod method = (ITestMethod)logMessage[UnitTestLogDecorator.TestMethodMetadata]; 
      ITestClass testClass = (ITestClass)logMessage[UnitTestLogDecorator.TestClassMetadata];       
      ScenarioResult sr = (ScenarioResult)logMessage[UnitTestLogDecorator.ScenarioResult];

      ResultText.AppendFormat(MESSAGE_FORMAT, testClass.Name, method.Name, result, sr);
      ResultText.AppendLine();
      ResultText.AppendLine();
       
    }

    private bool IsTestCaseCompletion(LogMessage message)
    {
      return message.HasDecorators(LogDecorator.TestOutcome, UnitTestLogDecorator.ScenarioResult);
    }

    
  }
}
